int x_offset, y_offset;
GskRenderNode *node;
GdkRGBA color;
+ graphene_rect_t node_bounds;
+ PangoRectangle ink_rect;
+
+ pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
+ pango_extents_to_pixels (&ink_rect, NULL);
+
+ /* Don't create empty nodes */
+ if (ink_rect.width == 0 || ink_rect.height == 0)
+ return;
gtk_snapshot_get_offset (crenderer->snapshot, &x_offset, &y_offset);
+
+ graphene_rect_init (&node_bounds,
+ x_offset + (float)x/PANGO_SCALE,
+ y_offset + (float)y/PANGO_SCALE + ink_rect.y,
+ ink_rect.x + ink_rect.width,
+ ink_rect.height);
+
+ /* Remove the snapshot offset from the position here again since
+ * gtk_snapshot_clips_rect will apply it to the given rect. */
+ if (gtk_snapshot_clips_rect (crenderer->snapshot,
+ &(cairo_rectangle_int_t){
+ node_bounds.origin.x - x_offset,
+ node_bounds.origin.y - y_offset,
+ ceil (node_bounds.size.width),
+ ceil (node_bounds.size.height)
+ }))
+ return;
+
get_color (crenderer, PANGO_RENDER_PART_FOREGROUND, &color);
- node = gsk_text_node_new (font, glyphs, &color, x_offset + (double)x/PANGO_SCALE, y_offset + (double)y/PANGO_SCALE);
+ node = gsk_text_node_new_with_bounds (font,
+ glyphs,
+ &color,
+ x_offset + (double)x/PANGO_SCALE,
+ y_offset + (double)y/PANGO_SCALE,
+ &node_bounds);
if (node == NULL)
return;